package com.ruoyi.web.sso.service.impl;

import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.web.sso.common.util.BusinessException;
import com.ruoyi.web.sso.common.util.ErrorCode;
import com.ruoyi.web.sso.util.HttpClientUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.sso.mapper.LiveRoomMapper;
import com.ruoyi.web.sso.domain.LiveRoom;
import com.ruoyi.web.sso.service.ILiveRoomService;
import com.ruoyi.common.core.text.Convert;

/**
 * 摄像头Service业务层处理
 * 
 * @author qiufeng
 * @date 2022-12-13
 */
@Service
public class LiveRoomServiceImpl implements ILiveRoomService 
{
    @Autowired
    private LiveRoomMapper liveRoomMapper;

    /**
     * 查询摄像头
     * 
     * @param id 摄像头主键
     * @return 摄像头
     */
    @Override
    public LiveRoom selectLiveRoomById(String id)
    {
        return liveRoomMapper.selectLiveRoomById(id);
    }

    /**
     * 查询摄像头列表
     * 
     * @param liveRoom 摄像头
     * @return 摄像头
     */
    @Override
    public List<LiveRoom> selectLiveRoomList(LiveRoom liveRoom)
    {
        return liveRoomMapper.selectLiveRoomList(liveRoom);
    }

    /**
     * 新增摄像头
     * 
     * @param liveRoom 摄像头
     * @return 结果
     */
    @Override
    public int insertLiveRoom(LiveRoom liveRoom)
    {
        liveRoom.setCreateTime(DateUtils.getNowDate());
        return liveRoomMapper.insertLiveRoom(liveRoom);
    }

    /**
     * 修改摄像头
     * 
     * @param liveRoom 摄像头
     * @return 结果
     */
    @Override
    public int updateLiveRoom(LiveRoom liveRoom)
    {
        return liveRoomMapper.updateLiveRoom(liveRoom);
    }

    /**
     * 批量删除摄像头
     * 
     * @param ids 需要删除的摄像头主键
     * @return 结果
     */
    @Override
    public int deleteLiveRoomByIds(String ids)
    {
        return liveRoomMapper.deleteLiveRoomByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除摄像头信息
     * 
     * @param id 摄像头主键
     * @return 结果
     */
    @Override
    public int deleteLiveRoomById(String id)
    {
        return liveRoomMapper.deleteLiveRoomById(id);
    }


    public static void main(String[] args) {
        String app_id = "appmviw9wd14656";
        String client_id = "xopjHTF14t34765";
        String secret_key =  "ufVwBfvvbJop17sJk9VhHvjkkMy1IgGU";
        String grant_type = "client_credential";

        String url1 = "https://api.xiaoe-tech.com/token?app_id="+app_id+"&client_id="+client_id+"&secret_key="+secret_key+"&grant_type="+grant_type;
        String json11 = HttpClientUtil.sendGet(url1).toString();
        JSONObject json12 = JSON.parseObject(json11);
        Map map11 = (Map) json12.get("data");
        String access_token = String.valueOf(map11.get("access_token"));
//        String access_token = "MWMZNDMZZTCTODU2ZC0ZODLHLTG2OTYTNTVLZWI3MMJIM2U0";

        String url  = "https://api.xiaoe-tech.com/xe.alive.list.get/1.0.0"+access_token;
//        String url  = "https://api.xiaoe-tech.com/xe.goods.list.get/4.0.0?access_token="+access_token;
        //关闭摄像头
        String responseJson = HttpClientUtil.sendPost(url).toString();
        JSONObject json = JSON.parseObject(responseJson);
        Map map = (Map) json.get("data");
        List<Map> mapList = (List<Map>) map.get("list");
        System.out.println(JSON.toJSON(mapList));



    }
}
